Library & Dataset

Using OLR

Inspect Dataset Using Training and Validation

OLR Equations

Inspect Dataset Using Training and Validation

vclust <- varclus (~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage , data=train.data)

# took out density since training has 0 d4 and it was not allowing do the plot

p <- plot(vclust)

par(mfrow=c(6,5))
plot.xmean.ordinaly (risk~angle+brick+wood+mixed+ density+EN +TC + TC_mature_soil + TC_saprolite_soil +  TC_weath_rock  + TC_unstable_structure  + T_construction  + spring +  landfill + garbage  + crack + leaning_wall + scars + downward_floor + tilted + fracture + conc_rainfall + wastewater + leak + septic_tank  + tree + ground_veg + deforestation + banana + drainage, data=train.data, cr=TRUE , subn=FALSE)

#angle + building+density+EN +TC + TC_mature_Soil + TC_saprolito +  TC_weath_rock + TC_rock + TC_geol_desfav + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + DepTaludeAterro + aterro + lixo + entulho + crack + belly_wall + scars + drawback + tilted + fracture + conc_rainfall_water + wastewater + leak + septic_tank + drainage + tree + ground_veg + deforestation + banana 

Diagnostic 2: Proportion (-5% of one of the parameters based on what is expected. Since some parameters have 2 predictors, others 5)

#library(plyr)
brick <- count(train.data$brick) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "brick")

wood <- count(train.data$wood) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wood")

mixed <- count(train.data$mixed) %>% 
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "mixed")

TC_mature_soil <- count(train.data$TC_mature_soil) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_mature_soil")

T_construction  <- count(train.data$T_construction ) %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "T_construction ")

spring <- count(train.data$spring) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "spring")

landfill <- count(train.data$landfill) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "landfill")

garbage <- count(train.data$garbage) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "garbage")

crack <- count(train.data$crack) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "crack")

leaning_wall <- count(train.data$leaning_wall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "leaning_wall")

scars <- count(train.data$scars) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "DepTaludeAterro")

downward_floor <- count(train.data$downward_floor) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "scars")

tilted <- count(train.data$tilted) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tilted")

conc_rainfall <- count(train.data$conc_rainfall) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall")

wastewater <- count(train.data$wastewater) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "wastewater")

leak <- count(train.data$leak) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "conc_rainfall_water")

septic_tank <- count(train.data$septic_tank) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "septic_tank")

angle <- count(train.data$angle) # angle A less than 5% but the rest are okay (3,50, 91, 277, 109) Expected=106
angle <- angle %>%
  mutate("Percentage"=(freq/106)*100)%>%
  mutate("Classifier" = "angle")

EN <- count(train.data$EN) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "EN")

TC <- count(train.data$TC)  %>%
  mutate ("Percentage"=(freq/265)*100) %>%
  mutate("Classifier" = "TC")

TC_saprolite_soil  <- count(train.data$TC_saprolite_soil )  %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_saprolite_soil ")

banana <- count(train.data$banana) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "banana")

drainage <- count(train.data$drainage) %>%
  mutate ("Percentage"=(freq/176.7)*100)%>%
  mutate("Classifier" = "drainage")

deforestation <- count(train.data$deforestation) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "deforestation")

TC_unstable_structure  <- count(train.data$TC_unstable_structure ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_unstable_structure ")


tree <- count(train.data$tree) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "tree")

ground_veg <- count(train.data$ground_veg) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "ground_veg")


density <- count(train.data$density)  %>% #(79, 415, 36) # d4 =0 
  mutate ("Percentage"=(freq/132.5)*100)%>%
  mutate("Classifier" = "density")

TC_weath_rock  <- count(train.data$TC_weath_rock ) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "TC_weath_rock ")

fracture <- count(train.data$fracture) %>%
  mutate ("Percentage"=(freq/265)*100)%>%
  mutate("Classifier" = "fracture")









df <- rbind(brick, wood, mixed, TC_mature_soil, T_construction, spring, landfill, garbage, crack, leaning_wall, scars, downward_floor, tilted, conc_rainfall, wastewater, leak, septic_tank, angle, EN, TC, TC_saprolite_soil,  banana, drainage, deforestation, TC_unstable_structure, tree, ground_veg,density, TC_weath_rock, fracture)

df
##        x freq  Percentage             Classifier
## 1  FALSE   33  12.4528302                  brick
## 2   TRUE  497 187.5471698                  brick
## 3  FALSE  458 172.8301887                   wood
## 4   TRUE   72  27.1698113                   wood
## 5  FALSE  495 186.7924528                  mixed
## 6   TRUE   35  13.2075472                  mixed
## 7  FALSE  264  99.6226415         TC_mature_soil
## 8   TRUE  266 100.3773585         TC_mature_soil
## 9  FALSE  213  80.3773585        T_construction 
## 10  TRUE  317 119.6226415        T_construction 
## 11 FALSE  513 193.5849057                 spring
## 12  TRUE   17   6.4150943                 spring
## 13 FALSE  329 124.1509434               landfill
## 14  TRUE  201  75.8490566               landfill
## 15 FALSE  353 133.2075472                garbage
## 16  TRUE  177  66.7924528                garbage
## 17 FALSE  443 167.1698113                  crack
## 18  TRUE   87  32.8301887                  crack
## 19 FALSE  500 188.6792453           leaning_wall
## 20  TRUE   30  11.3207547           leaning_wall
## 21 FALSE  329 124.1509434        DepTaludeAterro
## 22  TRUE  201  75.8490566        DepTaludeAterro
## 23 FALSE  468 176.6037736                  scars
## 24  TRUE   62  23.3962264                  scars
## 25 FALSE  424 160.0000000                 tilted
## 26  TRUE  106  40.0000000                 tilted
## 27 FALSE   20   7.5471698          conc_rainfall
## 28  TRUE  510 192.4528302          conc_rainfall
## 29 FALSE  205  77.3584906             wastewater
## 30  TRUE  325 122.6415094             wastewater
## 31 FALSE  342 129.0566038    conc_rainfall_water
## 32  TRUE  188  70.9433962    conc_rainfall_water
## 33 FALSE  525 198.1132075            septic_tank
## 34  TRUE    5   1.8867925            septic_tank
## 35     C   30  28.3018868                  angle
## 36     D  131 123.5849057                  angle
## 37     E  369 348.1132075                  angle
## 38 FALSE  337 127.1698113                     EN
## 39  TRUE  193  72.8301887                     EN
## 40 FALSE   31  11.6981132                     TC
## 41  TRUE  499 188.3018868                     TC
## 42 FALSE  444 167.5471698     TC_saprolite_soil 
## 43  TRUE   86  32.4528302     TC_saprolite_soil 
## 44 FALSE  361 136.2264151                 banana
## 45  TRUE  169  63.7735849                 banana
## 46     Y   71  40.1810979               drainage
## 47     P  231 130.7300509               drainage
## 48     N  228 129.0322581               drainage
## 49 FALSE  493 186.0377358          deforestation
## 50  TRUE   37  13.9622642          deforestation
## 51 FALSE  517 195.0943396 TC_unstable_structure 
## 52  TRUE   13   4.9056604 TC_unstable_structure 
## 53 FALSE  210  79.2452830                   tree
## 54  TRUE  320 120.7547170                   tree
## 55 FALSE  160  60.3773585             ground_veg
## 56  TRUE  370 139.6226415             ground_veg
## 57    d1   66  49.8113208                density
## 58    d2  424 320.0000000                density
## 59    d3   40  30.1886792                density
## 60 FALSE  521 196.6037736         TC_weath_rock 
## 61  TRUE    9   3.3962264         TC_weath_rock 
## 62 FALSE  529 199.6226415               fracture
## 63  TRUE    1   0.3773585               fracture

TC_weath_rock, TC_rock_TC_geol_desf, fracture, TC_rock

Equation 1

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana , data=train.data, x=TRUE , y=TRUE)

f1 <- lrm(risk ~ building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + tree + ground_veg + banana + septic_tank +TC_mature_Soil , data=train.data, x=TRUE , y=TRUE) print (f1 , latex =TRUE , coefs =5) stargazer(anova(f1), type=“text”, style=“default”)

# Equation 1

eq_OLR_01 <- polr(risk ~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil, data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_01))



p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error    t value      p value
## brickTRUE             -0.62286890  0.4531264 -1.3746029 8.462729e-02
## woodTRUE               1.14420641  0.3311403  3.4553522 2.747872e-04
## ENTRUE                 0.68534436  0.3596507  1.9055831 2.835216e-02
## TC_mature_soilTRUE     0.70731286  0.2215144  3.1930791 7.038218e-04
## T_constructionTRUE     0.19270082  0.3528399  0.5461425 2.924840e-01
## springTRUE            -0.24198349  0.6249096 -0.3872296 3.492931e-01
## landfillTRUE           0.24950144  0.3240544  0.7699370 2.206686e-01
## leakTRUE              -0.33603567  0.2343302 -1.4340262 7.578240e-02
## garbageTRUE           -0.00333971  0.2857214 -0.0116887 4.953370e-01
## crackTRUE              1.83902211  0.3245525  5.6663309 7.294382e-09
## leaning_wallTRUE       1.45470642  0.4781146  3.0425897 1.172760e-03
## scarsTRUE              3.63364977  0.3453973 10.5202039 3.486128e-26
## downward_floorTRUE     1.32342387  0.3553109  3.7246924 9.777676e-05
## tiltedTRUE             0.88083008  0.3038794  2.8986170 1.874062e-03
## septic_tankTRUE        0.36805649  1.0507361  0.3502844 3.630626e-01
## conc_rainfallTRUE      1.50842426  0.5154283  2.9265455 1.713747e-03
## wastewaterTRUE         0.78261548  0.2299758  3.4030344 3.332094e-04
## ground_vegTRUE         0.92544577  0.2478727  3.7335525 9.439893e-05
## angleD                 0.60222299  0.4638569  1.2982947 9.709305e-02
## angleE                 0.77028670  0.5317272  1.4486503 7.371763e-02
## TC_saprolite_soilTRUE  0.21591110  0.2785599  0.7750977 2.191410e-01
## R1|R2                  1.08026855  0.8553825  1.2629070 1.033113e-01
## R2|R3                  5.21764155  0.9041763  5.7706020 3.949442e-09
## R3|R4                 10.08231484  1.0113269  9.9693929 1.037466e-23
stargazer((ctable), type="text", style="default", digits = 2)
## 
## =======================================================
##                       Value  Std. Error t value p value
## -------------------------------------------------------
## brickTRUE             -0.62     0.45     -1.37   0.08  
## woodTRUE               1.14     0.33     3.46   0.0003 
## ENTRUE                 0.69     0.36     1.91    0.03  
## TC_mature_soilTRUE     0.71     0.22     3.19    0.001 
## T_constructionTRUE     0.19     0.35     0.55    0.29  
## springTRUE            -0.24     0.62     -0.39   0.35  
## landfillTRUE           0.25     0.32     0.77    0.22  
## leakTRUE              -0.34     0.23     -1.43   0.08  
## garbageTRUE           -0.003    0.29     -0.01   0.50  
## crackTRUE              1.84     0.32     5.67      0   
## leaning_wallTRUE       1.45     0.48     3.04    0.001 
## scarsTRUE              3.63     0.35     10.52     0   
## downward_floorTRUE     1.32     0.36     3.72   0.0001 
## tiltedTRUE             0.88     0.30     2.90    0.002 
## septic_tankTRUE        0.37     1.05     0.35    0.36  
## conc_rainfallTRUE      1.51     0.52     2.93    0.002 
## wastewaterTRUE         0.78     0.23     3.40   0.0003 
## ground_vegTRUE         0.93     0.25     3.73   0.0001 
## angleD                 0.60     0.46     1.30    0.10  
## angleE                 0.77     0.53     1.45    0.07  
## TC_saprolite_soilTRUE  0.22     0.28     0.78    0.22  
## R1| R2                 1.08     0.86     1.26    0.10  
## R2| R3                 5.22     0.90     5.77      0   
## R3| R4                10.08     1.01     9.97      0   
## -------------------------------------------------------

less p-value = 0.10 (TC_saprolitoTRUE,TaterroTRUE, DepTaludeAterroTRUE,DepTaludeAterroTRUE,landfillTRUE, construction_depositTRUE, leakTRUE)

par(mfrow=c(5,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=2, cex.sub=2, cex.main=2)

Creating function with four level

Equation 1

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN +  TC_mature_soil + T_construction + spring+ landfill+ leak+ garbage+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ septic_tank+ conc_rainfall+ wastewater+ ground_veg + angle + TC_saprolite_soil
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 33|Inf | 2.7408400| 0.980829253|-0.6931472|
## |                 |Yes|496|Inf | 2.3048048|-0.064538521|-2.0414481|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |                 |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |336|Inf | 1.8666608|-0.498147166|-2.3595519|
## |                 |Yes|193|Inf | 4.5591262| 0.894629235|-1.3733910|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |264|Inf | 1.9810015|-0.243622083|-2.2141741|
## |                 |Yes|265|Inf | 2.8134107| 0.235038339|-1.6695022|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |                 |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +-----------------+---+---+----+----------+------------+----------+
## |spring           |No |512|Inf | 2.2918898|-0.031252544|-2.0193376|
## |                 |Yes| 17|Inf |       Inf| 0.875468737|-0.1177830|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |328|Inf | 1.8132657|-0.550046337|-2.5848176|
## |                 |Yes|201|Inf | 5.2983174| 0.926762032|-1.2431935|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |341|Inf | 1.9627740|-0.253549066|-2.3385955|
## |                 |Yes|188|Inf | 3.6000482| 0.454472687|-1.3730491|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |353|Inf | 2.2067033|-0.198953957|-2.3057052|
## |                 |Yes|176|Inf | 2.6149598| 0.391280473|-1.3581235|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |                 |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |                 |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |                 |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |467|Inf | 2.1901071|-0.254034038|-2.2885333|
## |                 |Yes| 62|Inf |       Inf| 3.401197382|-0.3920421|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |                 |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +-----------------+---+---+----+----------+------------+----------+
## |septic_tank      |No |524|Inf | 2.3173689|-0.015267472|-1.9372144|
## |                 |Yes|  5|Inf |       Inf| 1.386294361|-0.4054651|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |                 |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |                 |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |                 |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 30|Inf |       Inf|-0.546543706|-3.3672958|
## |                 |D  |131|Inf | 4.1666652| 0.970357953|-1.3958638|
## |                 |E  |368|Inf | 1.9709898|-0.284512498|-2.0763881|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |443|Inf | 2.2047718|-0.076787143|-2.0845306|
## |                 |Yes| 86|Inf | 3.3202283| 0.376477571|-1.2602536|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=1, cex.sub=1)

Equation 2

  • parameters okay and so/so
  • porportion
  • excluded TC_geol_desf

f2 <- lrm(risk ~ angle + building + EN + TC_saprolito + Taterro + DepEncNatural + DepTaludeAterro + DepTaludeCorte + landfill + garbage + construction_deposit + crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + leak + drainage + TC_mature_Soil + density + TC + tree +ground_veg + deforestation + banana , data=train.data, x=TRUE , y=TRUE)

      stargazer(anova(f2), type="text", style="default")
eq_OLR_02 <- polr(risk ~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,
                  
                 data= train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_02))








p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                             Value Std. Error     t value      p value
## brickTRUE             -0.69036422  0.5569614 -1.23951903 1.075767e-01
## woodTRUE               0.91430850  0.3457010  2.64479537 4.087017e-03
## ENTRUE                 0.48675639  0.3796152  1.28223619 9.987990e-02
## TC_mature_soilTRUE     0.61769494  0.2338608  2.64129325 4.129510e-03
## T_constructionTRUE     0.26126106  0.3595060  0.72672239 2.336980e-01
## landfillTRUE           0.21539108  0.3277797  0.65712155 2.555514e-01
## leakTRUE              -0.47912088  0.2411871 -1.98651152 2.348828e-02
## garbageTRUE           -0.05829547  0.2914945 -0.19998823 4.207449e-01
## crackTRUE              1.95844874  0.3317082  5.90413065 1.772556e-09
## leaning_wallTRUE       1.59434661  0.4922470  3.23891598 5.999246e-04
## treeTRUE               0.02374714  0.2374989  0.09998839 4.601768e-01
## downward_floorTRUE     1.17479081  0.3591213  3.27129285 5.352849e-04
## tiltedTRUE             0.76950621  0.3065053  2.51058007 6.026649e-03
## ground_vegTRUE         0.70130555  0.2665432  2.63111439 4.255269e-03
## scarsTRUE              3.59524590  0.3507263 10.25085998 5.864762e-25
## mixedTRUE             -0.27473965  0.5351857 -0.51335387 3.038519e-01
## conc_rainfallTRUE      1.02955570  0.5464442  1.88410035 2.977570e-02
## wastewaterTRUE         0.56515040  0.2379838  2.37474310 8.780584e-03
## angleD                 0.51086114  0.4709446  1.08475843 1.390143e-01
## angleE                 0.74168257  0.5379186  1.37880078 8.397809e-02
## bananaTRUE             0.52107386  0.2472134  2.10779007 1.752458e-02
## drainage.L             1.23970914  0.2803223  4.42244285 4.879558e-06
## drainage.Q            -0.15175369  0.1872887 -0.81026621 2.088936e-01
## TC_saprolite_soilTRUE  0.14585715  0.2885272  0.50552305 3.065958e-01
## TCTRUE                -0.34705833  0.4861389 -0.71390769 2.376421e-01
## deforestationTRUE      0.18296402  0.4128509  0.44317216 3.288206e-01
## R1|R2                 -0.09014790  1.0771711 -0.08368949 4.666517e-01
## R2|R3                  4.32830466  1.0948499  3.95333146 3.853528e-05
## R3|R4                  9.25964771  1.1864663  7.80439174 2.989460e-15
stargazer((ctable), type="text", style="default", digits=2)
## 
## ======================================================
##                       Value Std. Error t value p value
## ------------------------------------------------------
## brickTRUE             -0.69    0.56     -1.24   0.11  
## woodTRUE              0.91     0.35     2.64    0.004 
## ENTRUE                0.49     0.38     1.28    0.10  
## TC_mature_soilTRUE    0.62     0.23     2.64    0.004 
## T_constructionTRUE    0.26     0.36     0.73    0.23  
## landfillTRUE          0.22     0.33     0.66    0.26  
## leakTRUE              -0.48    0.24     -1.99   0.02  
## garbageTRUE           -0.06    0.29     -0.20   0.42  
## crackTRUE             1.96     0.33     5.90      0   
## leaning_wallTRUE      1.59     0.49     3.24    0.001 
## treeTRUE              0.02     0.24     0.10    0.46  
## downward_floorTRUE    1.17     0.36     3.27    0.001 
## tiltedTRUE            0.77     0.31     2.51    0.01  
## ground_vegTRUE        0.70     0.27     2.63    0.004 
## scarsTRUE             3.60     0.35     10.25     0   
## mixedTRUE             -0.27    0.54     -0.51   0.30  
## conc_rainfallTRUE     1.03     0.55     1.88    0.03  
## wastewaterTRUE        0.57     0.24     2.37    0.01  
## angleD                0.51     0.47     1.08    0.14  
## angleE                0.74     0.54     1.38    0.08  
## bananaTRUE            0.52     0.25     2.11    0.02  
## drainage.L            1.24     0.28     4.42   0.0000 
## drainage.Q            -0.15    0.19     -0.81   0.21  
## TC_saprolite_soilTRUE 0.15     0.29     0.51    0.31  
## TCTRUE                -0.35    0.49     -0.71   0.24  
## deforestationTRUE     0.18     0.41     0.44    0.33  
## R1| R2                -0.09    1.08     -0.08   0.47  
## R2| R3                4.33     1.09     3.95   0.0000 
## R3| R4                9.26     1.19     7.80      0   
## ------------------------------------------------------
par(mfrow=c(6,4))
plot.xmean.ordinaly (risk~ brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation
          ,data=train.data, cr=TRUE , subn=FALSE ,  cex.lab=1.5, cex.axis=4, cex.sub=4, cex.main=4)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ EN+  TC_mature_soil+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ mixed+ conc_rainfall+ wastewater+ angle+ banana+ drainage+ TC_saprolite_soil+ TC+ deforestation,data=train.data
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +-----------------+---+---+----+----------+------------+----------+
## |                 |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +-----------------+---+---+----+----------+------------+----------+
## |brick            |No | 33|Inf | 2.7408400| 0.980829253|-0.6931472|
## |                 |Yes|496|Inf | 2.3048048|-0.064538521|-2.0414481|
## +-----------------+---+---+----+----------+------------+----------+
## |wood             |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |                 |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +-----------------+---+---+----+----------+------------+----------+
## |EN               |No |336|Inf | 1.8666608|-0.498147166|-2.3595519|
## |                 |Yes|193|Inf | 4.5591262| 0.894629235|-1.3733910|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_mature_soil   |No |264|Inf | 1.9810015|-0.243622083|-2.2141741|
## |                 |Yes|265|Inf | 2.8134107| 0.235038339|-1.6695022|
## +-----------------+---+---+----+----------+------------+----------+
## |T_construction   |No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |                 |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +-----------------+---+---+----+----------+------------+----------+
## |landfill         |No |328|Inf | 1.8132657|-0.550046337|-2.5848176|
## |                 |Yes|201|Inf | 5.2983174| 0.926762032|-1.2431935|
## +-----------------+---+---+----+----------+------------+----------+
## |leak             |No |341|Inf | 1.9627740|-0.253549066|-2.3385955|
## |                 |Yes|188|Inf | 3.6000482| 0.454472687|-1.3730491|
## +-----------------+---+---+----+----------+------------+----------+
## |garbage          |No |353|Inf | 2.2067033|-0.198953957|-2.3057052|
## |                 |Yes|176|Inf | 2.6149598| 0.391280473|-1.3581235|
## +-----------------+---+---+----+----------+------------+----------+
## |crack            |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |                 |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +-----------------+---+---+----+----------+------------+----------+
## |leaning_wall     |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |                 |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +-----------------+---+---+----+----------+------------+----------+
## |tree             |No |209|Inf | 1.6739764|-0.538996501|-2.1919195|
## |                 |Yes|320|Inf | 3.0845278| 0.340759489|-1.7593242|
## +-----------------+---+---+----+----------+------------+----------+
## |downward_floor   |No |467|Inf | 2.1901071|-0.254034038|-2.2885333|
## |                 |Yes| 62|Inf |       Inf| 3.401197382|-0.3920421|
## +-----------------+---+---+----+----------+------------+----------+
## |tilted           |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |                 |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +-----------------+---+---+----+----------+------------+----------+
## |ground_veg       |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |                 |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +-----------------+---+---+----+----------+------------+----------+
## |scars            |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |                 |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +-----------------+---+---+----+----------+------------+----------+
## |mixed            |No |494|Inf | 2.3003604|-0.064799993|-1.9787000|
## |                 |Yes| 35|Inf | 2.8033604| 0.916290732|-1.2163953|
## +-----------------+---+---+----+----------+------------+----------+
## |conc_rainfall    |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |                 |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +-----------------+---+---+----+----------+------------+----------+
## |wastewater       |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |                 |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +-----------------+---+---+----+----------+------------+----------+
## |angle            |C  | 30|Inf |       Inf|-0.546543706|-3.3672958|
## |                 |D  |131|Inf | 4.1666652| 0.970357953|-1.3958638|
## |                 |E  |368|Inf | 1.9709898|-0.284512498|-2.0763881|
## +-----------------+---+---+----+----------+------------+----------+
## |banana           |No |360|Inf | 1.9459101|-0.290923566|-2.1667344|
## |                 |Yes|169|Inf | 4.4248466| 0.622942922|-1.4932665|
## +-----------------+---+---+----+----------+------------+----------+
## |drainage         |Y  | 71|Inf | 0.6720938|-2.063693185|-4.2484952|
## |                 |P  |230|Inf | 2.4662145|-0.496936512|-2.5933873|
## |                 |N  |228|Inf | 3.7977339| 1.052361271|-1.2443241|
## +-----------------+---+---+----+----------+------------+----------+
## |TC_saprolite_soil|No |443|Inf | 2.2047718|-0.076787143|-2.0845306|
## |                 |Yes| 86|Inf | 3.3202283| 0.376477571|-1.2602536|
## +-----------------+---+---+----+----------+------------+----------+
## |TC               |No | 31|Inf |       Inf| 0.741937345|-1.4271164|
## |                 |Yes|498|Inf | 2.2613197|-0.048202102|-1.9505079|
## +-----------------+---+---+----+----------+------------+----------+
## |deforestation    |No |492|Inf | 2.3978953| 0.048790164|-1.8823967|
## |                 |Yes| 37|Inf | 1.6422277|-0.733969175|-2.4277482|
## +-----------------+---+---+----+----------+------------+----------+
## |Overall          |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +-----------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=1, cex.axis=2, cex.sub=1)

Equation 3

  • parameters okay and so/so
  • porportion
  • p-value based equation 2 > 0.5

f3 <- lrm(risk ~ angle +building + EN + DepTaludeAterro+ DepTaludeCorte+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall_water+ wastewater+ tree + TC , data=train.data, x=TRUE , y=TRUE) stargazer(anova(f3), type=“text”, style=“default”)

# x=TRUE, y=TRUE used by resid() below 

eq_OLR_03 <- polr(risk ~ wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, data=train.data
           ,  method = "logistic", Hess = TRUE)
ctable <- coef(summary(eq_OLR_03))


p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                          Value Std. Error    t value      p value
## woodTRUE            0.85830150  0.3260349  2.6325445 4.237396e-03
## TC_mature_soilTRUE  0.53837735  0.2212512  2.4333302 7.480325e-03
## T_constructionTRUE  0.23815042  0.2856075  0.8338381 2.021861e-01
## landfillTRUE        0.23432679  0.2913347  0.8043216 2.106056e-01
## crackTRUE           1.98220581  0.3210796  6.1735656 3.338341e-10
## leaning_wallTRUE    1.59155919  0.4866439  3.2704802 5.368253e-04
## treeTRUE            0.06975326  0.2272725  0.3069146 3.794542e-01
## downward_floorTRUE  1.03553738  0.3474878  2.9800687 1.440919e-03
## tiltedTRUE          0.71385198  0.2973872  2.4004128 8.188297e-03
## ground_vegTRUE      0.69756485  0.2593014  2.6901704 3.570777e-03
## scarsTRUE           3.58807311  0.3472203 10.3337087 2.480240e-25
## conc_rainfallTRUE   1.02117774  0.5383283  1.8969422 2.891778e-02
## wastewaterTRUE      0.51860275  0.2315241  2.2399510 1.254705e-02
## bananaTRUE          0.48288701  0.2367276  2.0398426 2.068300e-02
## drainage.L          1.19539241  0.2743370  4.3573875 6.581205e-06
## drainage.Q         -0.11222219  0.1844603 -0.6083813 2.714673e-01
## R1|R2               0.21961839  0.5230872  0.4198505 3.372973e-01
## R2|R3               4.54030875  0.5819245  7.8022302 3.041129e-15
## R3|R4               9.39510325  0.7217471 13.0171687 4.886389e-39
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.86     0.33     2.63    0.004 
## TC_mature_soilTRUE 0.54     0.22     2.43    0.01  
## T_constructionTRUE 0.24     0.29     0.83    0.20  
## landfillTRUE       0.23     0.29     0.80    0.21  
## crackTRUE          1.98     0.32     6.17      0   
## leaning_wallTRUE   1.59     0.49     3.27    0.001 
## treeTRUE           0.07     0.23     0.31    0.38  
## downward_floorTRUE 1.04     0.35     2.98    0.001 
## tiltedTRUE         0.71     0.30     2.40    0.01  
## ground_vegTRUE     0.70     0.26     2.69    0.004 
## scarsTRUE          3.59     0.35     10.33     0   
## conc_rainfallTRUE  1.02     0.54     1.90    0.03  
## wastewaterTRUE     0.52     0.23     2.24    0.01  
## bananaTRUE         0.48     0.24     2.04    0.02  
## drainage.L         1.20     0.27     4.36   0.0000 
## drainage.Q         -0.11    0.18     -0.61   0.27  
## R1| R2             0.22     0.52     0.42    0.34  
## R2| R3             4.54     0.58     7.80      0   
## R3| R4             9.40     0.72     13.02     0   
## ---------------------------------------------------
#print (f3 , latex =TRUE , coefs =5)
par(mfrow=c(3,5))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage,,
          data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ landfill+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |              |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |264|Inf | 1.9810015|-0.243622083|-2.2141741|
## |              |Yes|265|Inf | 2.8134107| 0.235038339|-1.6695022|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |              |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |328|Inf | 1.8132657|-0.550046337|-2.5848176|
## |              |Yes|201|Inf | 5.2983174| 0.926762032|-1.2431935|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |              |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |              |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.6739764|-0.538996501|-2.1919195|
## |              |Yes|320|Inf | 3.0845278| 0.340759489|-1.7593242|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |467|Inf | 2.1901071|-0.254034038|-2.2885333|
## |              |Yes| 62|Inf |       Inf| 3.401197382|-0.3920421|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |              |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |              |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |              |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |              |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |              |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |360|Inf | 1.9459101|-0.290923566|-2.1667344|
## |              |Yes|169|Inf | 4.4248466| 0.622942922|-1.4932665|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 71|Inf | 0.6720938|-2.063693185|-4.2484952|
## |              |P  |230|Inf | 2.4662145|-0.496936512|-2.5933873|
## |              |N  |228|Inf | 3.7977339| 1.052361271|-1.2443241|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.6, cex.axis=0.6, cex.sub=0.6)

Equation 4

  • p-value equation 3 > 0.05 (banana, DepTaludeCorte)
  • consider proportion
  • paremeters okay & so/so
  • fashion order

f4 <- lrm(risk ~ building + EN
+ DepEncNatural
+ crack + leaning_wall + scars + downward_floor +tilted + conc_rainfall_water + wastewater + drainage + TC_mature_Soil + TC + +ground_veg
,data=train.data, x=TRUE , y=TRUE) # x=TRUE, y=TRUE used by resid() below #print (f4 , latex =TRUE , coefs =5) stargazer(anova(f4), type=“text”, style=“default”)

eq_OLR_04 <- polr(risk~ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
                  , data= train.data
           ,  method = "logistic", Hess = TRUE)
p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value

ctable <- coef(summary(eq_OLR_04))

ctable <- cbind(ctable, "p value" = p )
## Warning in cbind(ctable, `p value` = p): number of rows of result is not a
## multiple of vector length (arg 2)
ctable
##                          Value Std. Error    t value      p value
## woodTRUE            0.84885165  0.3253134  2.6093349 4.237396e-03
## TC_mature_soilTRUE  0.51097907  0.2183982  2.3396666 7.480325e-03
## T_constructionTRUE  0.37433338  0.2301013  1.6268197 2.021861e-01
## crackTRUE           2.00201945  0.3206195  6.2442224 2.106056e-01
## leaning_wallTRUE    1.56548583  0.4865142  3.2177599 3.338341e-10
## treeTRUE            0.05851965  0.2268813  0.2579307 5.368253e-04
## downward_floorTRUE  1.06459936  0.3454842  3.0814700 3.794542e-01
## tiltedTRUE          0.75370913  0.2931559  2.5710184 1.440919e-03
## ground_vegTRUE      0.71855215  0.2579941  2.7851500 8.188297e-03
## scarsTRUE           3.59428167  0.3471872 10.3525762 3.570777e-03
## conc_rainfallTRUE   1.03576481  0.5385751  1.9231577 2.480240e-25
## wastewaterTRUE      0.49091118  0.2289552  2.1441361 2.891778e-02
## bananaTRUE          0.48480360  0.2366466  2.0486400 1.254705e-02
## drainage.L          1.20804445  0.2738221  4.4117863 2.068300e-02
## drainage.Q         -0.11228051  0.1843756 -0.6089771 6.581205e-06
## R1|R2               0.22549862  0.5237415  0.4305533 2.714673e-01
## R2|R3               4.54218190  0.5826881  7.7952200 3.372973e-01
## R3|R4               9.38943920  0.7219268 13.0060820 3.041129e-15
stargazer((ctable), type="text", style="default", digits=2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## woodTRUE           0.85     0.33     2.61    0.004 
## TC_mature_soilTRUE 0.51     0.22     2.34    0.01  
## T_constructionTRUE 0.37     0.23     1.63    0.20  
## crackTRUE          2.00     0.32     6.24    0.21  
## leaning_wallTRUE   1.57     0.49     3.22      0   
## treeTRUE           0.06     0.23     0.26    0.001 
## downward_floorTRUE 1.06     0.35     3.08    0.38  
## tiltedTRUE         0.75     0.29     2.57    0.001 
## ground_vegTRUE     0.72     0.26     2.79    0.01  
## scarsTRUE          3.59     0.35     10.35   0.004 
## conc_rainfallTRUE  1.04     0.54     1.92      0   
## wastewaterTRUE     0.49     0.23     2.14    0.03  
## bananaTRUE         0.48     0.24     2.05    0.01  
## drainage.L         1.21     0.27     4.41    0.02  
## drainage.Q         -0.11    0.18     -0.61  0.0000 
## R1| R2             0.23     0.52     0.43    0.27  
## R2| R3             4.54     0.58     7.80    0.34  
## R3| R4             9.39     0.72     13.01     0   
## ---------------------------------------------------
par(mfrow=c(4,4))
plot.xmean.ordinaly (risk ~  wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ tree+ downward_floor+ tilted+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana+ drainage
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |              |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |264|Inf | 1.9810015|-0.243622083|-2.2141741|
## |              |Yes|265|Inf | 2.8134107| 0.235038339|-1.6695022|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |              |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |              |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |              |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.6739764|-0.538996501|-2.1919195|
## |              |Yes|320|Inf | 3.0845278| 0.340759489|-1.7593242|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |467|Inf | 2.1901071|-0.254034038|-2.2885333|
## |              |Yes| 62|Inf |       Inf| 3.401197382|-0.3920421|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |              |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |              |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |              |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |              |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |              |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |360|Inf | 1.9459101|-0.290923566|-2.1667344|
## |              |Yes|169|Inf | 4.4248466| 0.622942922|-1.4932665|
## +--------------+---+---+----+----------+------------+----------+
## |drainage      |Y  | 71|Inf | 0.6720938|-2.063693185|-4.2484952|
## |              |P  |230|Inf | 2.4662145|-0.496936512|-2.5933873|
## |              |N  |228|Inf | 3.7977339| 1.052361271|-1.2443241|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Equation 5 - Based on Equation 1

  • based on Eq 1
  • less p-value > 0.10 (
# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_05 <- polr(risk ~ brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_05))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                         Value Std. Error    t value      p value
## brickTRUE          -0.4370018  0.4423303 -0.9879536 1.615877e-01
## woodTRUE            1.0207921  0.3198713  3.1912584 7.082727e-04
## TC_mature_soilTRUE  0.6200433  0.2151391  2.8820584 1.975433e-03
## T_constructionTRUE  0.3959872  0.2234254  1.7723462 3.816855e-02
## crackTRUE           1.8795793  0.3131351  6.0024541 9.717861e-10
## leaning_wallTRUE    1.4240258  0.4758818  2.9923935 1.383996e-03
## scarsTRUE           3.6689232  0.3436234 10.6771644 6.509383e-27
## downward_floorTRUE  1.2784517  0.3427868  3.7295824 9.589869e-05
## tiltedTRUE          0.9078147  0.2914811  3.1144890 9.213191e-04
## conc_rainfallTRUE   1.5125790  0.5094811  2.9688618 1.494525e-03
## wastewaterTRUE      0.7065394  0.2212379  3.1935729 7.026194e-04
## ground_vegTRUE      1.0266533  0.2359413  4.3513073 6.766411e-06
## R1|R2               0.5181656  0.6575352  0.7880423 2.153360e-01
## R2|R3               4.5736433  0.7141022  6.4047463 7.530980e-11
## R3|R4               9.3408231  0.8211153 11.3757745 2.760526e-30
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.44    0.44     -0.99   0.16  
## woodTRUE           1.02     0.32     3.19    0.001 
## TC_mature_soilTRUE 0.62     0.22     2.88    0.002 
## T_constructionTRUE 0.40     0.22     1.77    0.04  
## crackTRUE          1.88     0.31     6.00      0   
## leaning_wallTRUE   1.42     0.48     2.99    0.001 
## scarsTRUE          3.67     0.34     10.68     0   
## downward_floorTRUE 1.28     0.34     3.73   0.0001 
## tiltedTRUE         0.91     0.29     3.11    0.001 
## conc_rainfallTRUE  1.51     0.51     2.97    0.001 
## wastewaterTRUE     0.71     0.22     3.19    0.001 
## ground_vegTRUE     1.03     0.24     4.35   0.0000 
## R1| R2             0.52     0.66     0.79    0.22  
## R2| R3             4.57     0.71     6.40      0   
## R3| R4             9.34     0.82     11.38     0   
## ---------------------------------------------------
par(mfrow=c(3,4))
plot.xmean.ordinaly (risk ~  brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+  TC_mature_soil+ T_construction+ crack+ leaning_wall+ scars+ downward_floor+ tilted+ conc_rainfall+ wastewater+ ground_veg
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 33|Inf | 2.7408400| 0.980829253|-0.6931472|
## |              |Yes|496|Inf | 2.3048048|-0.064538521|-2.0414481|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |              |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +--------------+---+---+----+----------+------------+----------+
## |TC_mature_soil|No |264|Inf | 1.9810015|-0.243622083|-2.2141741|
## |              |Yes|265|Inf | 2.8134107| 0.235038339|-1.6695022|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |              |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |              |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |              |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |              |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +--------------+---+---+----+----------+------------+----------+
## |downward_floor|No |467|Inf | 2.1901071|-0.254034038|-2.2885333|
## |              |Yes| 62|Inf |       Inf| 3.401197382|-0.3920421|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |              |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |              |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |              |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |              |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

OLR Equation 6

# x=TRUE, y=TRUE used by resid() below 
#print (f1 , latex =TRUE , coefs =5)
#stargazer(anova(f1), type="text", style="default")

eq_OLR_06 <- polr(risk ~ brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana,  data= train.data
           ,  method = "logistic", Hess = TRUE)

ctable <- coef(summary(eq_OLR_06))

p<- pnorm(abs(ctable[, "t value"]), lower.tail = FALSE*2) #computes p value
ctable <- cbind(ctable, "p value" = p )

ctable
##                           Value Std. Error     t value      p value
## brickTRUE          -0.942889607  0.5407213 -1.74376275 4.060023e-02
## woodTRUE            0.859549174  0.3217759  2.67126613 3.778285e-03
## mixedTRUE          -0.023613745  0.5181062 -0.04557704 4.818237e-01
## ENTRUE              0.644194626  0.3670085  1.75525824 3.960757e-02
## TCTRUE              0.015391373  0.4503644  0.03417537 4.863687e-01
## T_constructionTRUE  0.254507322  0.3403651  0.74774789 2.273061e-01
## landfillTRUE        0.268683843  0.3128988  0.85869241 1.952551e-01
## leakTRUE           -0.171162134  0.2287266 -0.74832632 2.271317e-01
## garbageTRUE        -0.009183685  0.2798431 -0.03281727 4.869102e-01
## crackTRUE           1.764284254  0.3153780  5.59418920 1.108276e-08
## leaning_wallTRUE    1.458922795  0.4845785  3.01070468 1.303211e-03
## treeTRUE            0.006606937  0.2279786  0.02898051 4.884401e-01
## tiltedTRUE          0.902937852  0.2955678  3.05492585 1.125581e-03
## angleD              0.554697232  0.4602188  1.20529025 1.140456e-01
## angleE              0.858086750  0.5233230  1.63968862 5.053496e-02
## ground_vegTRUE      0.841494315  0.2564667  3.28110510 5.170060e-04
## scarsTRUE           3.762910122  0.3462670 10.86707843 8.270655e-28
## conc_rainfallTRUE   1.834223348  0.5161322  3.55378579 1.898642e-04
## wastewaterTRUE      0.681293972  0.2246589  3.03257111 1.212400e-03
## bananaTRUE          0.656452968  0.2391610  2.74481643 3.027238e-03
## R1|R2               0.932373154  1.0307023  0.90459985 1.828387e-01
## R2|R3               4.951454233  1.0613488  4.66524701 1.541233e-06
## R3|R4               9.699844620  1.1534212  8.40962923 2.056544e-17
stargazer((ctable), type="text", style="default", digits = 2)
## 
## ===================================================
##                    Value Std. Error t value p value
## ---------------------------------------------------
## brickTRUE          -0.94    0.54     -1.74   0.04  
## woodTRUE           0.86     0.32     2.67    0.004 
## mixedTRUE          -0.02    0.52     -0.05   0.48  
## ENTRUE             0.64     0.37     1.76    0.04  
## TCTRUE             0.02     0.45     0.03    0.49  
## T_constructionTRUE 0.25     0.34     0.75    0.23  
## landfillTRUE       0.27     0.31     0.86    0.20  
## leakTRUE           -0.17    0.23     -0.75   0.23  
## garbageTRUE        -0.01    0.28     -0.03   0.49  
## crackTRUE          1.76     0.32     5.59      0   
## leaning_wallTRUE   1.46     0.48     3.01    0.001 
## treeTRUE           0.01     0.23     0.03    0.49  
## tiltedTRUE         0.90     0.30     3.05    0.001 
## angleD             0.55     0.46     1.21    0.11  
## angleE             0.86     0.52     1.64    0.05  
## ground_vegTRUE     0.84     0.26     3.28    0.001 
## scarsTRUE          3.76     0.35     10.87     0   
## conc_rainfallTRUE  1.83     0.52     3.55   0.0002 
## wastewaterTRUE     0.68     0.22     3.03    0.001 
## bananaTRUE         0.66     0.24     2.74    0.003 
## R1| R2             0.93     1.03     0.90    0.18  
## R2| R3             4.95     1.06     4.67   0.0000 
## R3| R4             9.70     1.15     8.41      0   
## ---------------------------------------------------
par(mfrow=c(5,4))
plot.xmean.ordinaly (risk ~  brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
          ,data=train.data, cr=TRUE , subn=FALSE , cex.points =0.65)

sf <- function (y) {
        c('y>=1' = qlogis(mean(y>=1)),
          'y>=2' = qlogis(mean(y>=2)),
           'y>=3' = qlogis(mean(y>=3)),
            'y>=4' = qlogis(mean(y>=4)))
}

s<-with(train.data, summary(as.numeric(risk)~brick+ wood+ mixed+ EN+ TC+ T_construction+ landfill+ leak+ garbage+ crack+ leaning_wall+ tree+ tilted+ angle+ ground_veg+ scars+ conc_rainfall+ wastewater+ banana
, fun=sf))
s
## as.numeric(risk)     N= 529 , 1 Missing 
## 
## +--------------+---+---+----+----------+------------+----------+
## |              |   |N  |y>=1|y>=2      |y>=3        |y>=4      |
## +--------------+---+---+----+----------+------------+----------+
## |brick         |No | 33|Inf | 2.7408400| 0.980829253|-0.6931472|
## |              |Yes|496|Inf | 2.3048048|-0.064538521|-2.0414481|
## +--------------+---+---+----+----------+------------+----------+
## |wood          |No |457|Inf | 2.2143609|-0.171094494|-2.1899518|
## |              |Yes| 72|Inf | 3.5553481| 1.174119841|-0.8209806|
## +--------------+---+---+----+----------+------------+----------+
## |mixed         |No |494|Inf | 2.3003604|-0.064799993|-1.9787000|
## |              |Yes| 35|Inf | 2.8033604| 0.916290732|-1.2163953|
## +--------------+---+---+----+----------+------------+----------+
## |EN            |No |336|Inf | 1.8666608|-0.498147166|-2.3595519|
## |              |Yes|193|Inf | 4.5591262| 0.894629235|-1.3733910|
## +--------------+---+---+----+----------+------------+----------+
## |TC            |No | 31|Inf |       Inf| 0.741937345|-1.4271164|
## |              |Yes|498|Inf | 2.2613197|-0.048202102|-1.9505079|
## +--------------+---+---+----+----------+------------+----------+
## |T_construction|No |213|Inf | 1.6610253|-0.822825004|-3.0106209|
## |              |Yes|316|Inf | 3.1487834| 0.531130890|-1.4925166|
## +--------------+---+---+----+----------+------------+----------+
## |landfill      |No |328|Inf | 1.8132657|-0.550046337|-2.5848176|
## |              |Yes|201|Inf | 5.2983174| 0.926762032|-1.2431935|
## +--------------+---+---+----+----------+------------+----------+
## |leak          |No |341|Inf | 1.9627740|-0.253549066|-2.3385955|
## |              |Yes|188|Inf | 3.6000482| 0.454472687|-1.3730491|
## +--------------+---+---+----+----------+------------+----------+
## |garbage       |No |353|Inf | 2.2067033|-0.198953957|-2.3057052|
## |              |Yes|176|Inf | 2.6149598| 0.391280473|-1.3581235|
## +--------------+---+---+----+----------+------------+----------+
## |crack         |No |442|Inf | 2.1772738|-0.338023827|-2.6561518|
## |              |Yes| 87|Inf | 3.7495041| 2.436116486|-0.2076394|
## +--------------+---+---+----+----------+------------+----------+
## |leaning_wall  |No |499|Inf | 2.2635346|-0.100284363|-2.0884914|
## |              |Yes| 30|Inf |       Inf| 2.197224577|-0.2682640|
## +--------------+---+---+----+----------+------------+----------+
## |tree          |No |209|Inf | 1.6739764|-0.538996501|-2.1919195|
## |              |Yes|320|Inf | 3.0845278| 0.340759489|-1.7593242|
## +--------------+---+---+----+----------+------------+----------+
## |tilted        |No |423|Inf | 2.0794415|-0.437088297|-2.4696392|
## |              |Yes|106|Inf |       Inf| 2.505525937|-0.7073318|
## +--------------+---+---+----+----------+------------+----------+
## |angle         |C  | 30|Inf |       Inf|-0.546543706|-3.3672958|
## |              |D  |131|Inf | 4.1666652| 0.970357953|-1.3958638|
## |              |E  |368|Inf | 1.9709898|-0.284512498|-2.0763881|
## +--------------+---+---+----+----------+------------+----------+
## |ground_veg    |No |160|Inf | 1.2729657|-1.132228899|-2.5123056|
## |              |Yes|369|Inf | 3.3928291| 0.446287103|-1.7208515|
## +--------------+---+---+----+----------+------------+----------+
## |scars         |No |328|Inf | 1.8132657|-1.286396208|-4.3944492|
## |              |Yes|201|Inf | 5.2983174| 3.183248647|-0.7610978|
## +--------------+---+---+----+----------+------------+----------+
## |conc_rainfall |No | 20|Inf |-0.2006707|-2.944438979|      -Inf|
## |              |Yes|509|Inf | 2.5755765| 0.066822496|-1.8695372|
## +--------------+---+---+----+----------+------------+----------+
## |wastewater    |No |205|Inf | 1.6875557|-0.529079064|-2.7777835|
## |              |Yes|324|Inf | 3.0252911| 0.323787077|-1.5656353|
## +--------------+---+---+----+----------+------------+----------+
## |banana        |No |360|Inf | 1.9459101|-0.290923566|-2.1667344|
## |              |Yes|169|Inf | 4.4248466| 0.622942922|-1.4932665|
## +--------------+---+---+----+----------+------------+----------+
## |Overall       |   |529|Inf | 2.3277965|-0.003780723|-1.9138903|
## +--------------+---+---+----+----------+------------+----------+
plot(s, which=1:4, pch=1:4, xlab='logit', main=' ', xlim=c(-5,5), cex.lab=0.7, cex.axis=0.5, cex.sub=0.5)

Predicion on test data Eq 1: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel1 <- predict(eq_OLR_01, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_01, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel1)
##     predictedLevel1
##      R1 R2 R3 R4
##   R1  3 15  1  0
##   R2  0 88  5  0
##   R3  0 12 61 11
##   R4  0  0 12 16
p1 <- mean(as.character(test.data$risk) != as.character(predictedLevel1)) #misclassification error
p1 
## [1] 0.25

Predicion on test data Eq 2: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel2 <- predict(eq_OLR_02, test.data) # predict the levels directly

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel2)
##     predictedLevel2
##      R1 R2 R3 R4
##   R1  5 14  0  0
##   R2  3 85  5  0
##   R3  0 12 59 13
##   R4  0  0 13 15
p2 <- mean(as.character(test.data$risk) != as.character(predictedLevel2))
p2
## [1] 0.2678571

Predicion on test data Eq 3: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel3 <- predict(eq_OLR_03, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_03, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel3)
##     predictedLevel3
##      R1 R2 R3 R4
##   R1  5 13  1  0
##   R2  4 82  7  0
##   R3  0 12 62 10
##   R4  0  0 11 17
p3 <- mean(as.character(test.data$risk) != as.character(predictedLevel3))
p3
## [1] 0.2589286

Predicion on test data Eq 4: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel4 <- predict(eq_OLR_04, test.data) # predict the levels directly

predictedScores1 <- predict(eq_OLR_04, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel4)
##     predictedLevel4
##      R1 R2 R3 R4
##   R1  5 14  0  0
##   R2  4 84  5  0
##   R3  0 11 63 10
##   R4  0  0 11 17
p4 <- mean(as.character(test.data$risk) != as.character(predictedLevel4))
p4
## [1] 0.2455357

Predicion on test data Eq 5: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel5 <- predict(eq_OLR_05, test.data) # predict the levels directly

predictedScores5 <- predict(eq_OLR_05, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel5)
##     predictedLevel5
##      R1 R2 R3 R4
##   R1  2 16  1  0
##   R2  0 88  5  0
##   R3  0 12 59 13
##   R4  0  0 11 17
p5 <- mean(as.character(test.data$risk) != as.character(predictedLevel5))
p5
## [1] 0.2589286

Predicion on test data Eq 6: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

predictedLevel6 <- predict(eq_OLR_06, test.data) # predict the levels directly

predictedScores6 <- predict(eq_OLR_06, test.data, type="p") 
 # predict the probabilites

## Confusion matrix and misclassification error
table(test.data$risk, predictedLevel6)
##     predictedLevel6
##      R1 R2 R3 R4
##   R1  3 15  1  0
##   R2  1 87  5  0
##   R3  0 14 63  7
##   R4  0  0 11 17
p6 <- mean(as.character(test.data$risk) != as.character(predictedLevel6))
p6
## [1] 0.2410714

Predicion on test data Eq 7: http://r-statistics.co/Ordinal-Logistic-Regression-With-R.html

#Table 

df2 <- data.frame(
  
  "Equations"=c(1:6), 
  "Predicted"=c(1-p1, 
                1-p2,
                1-p3,
                1-p4,
                1-p5,
                1-p6
               
              
    
    
  )
  
  
  
)

df2
##   Equations Predicted
## 1         1 0.7500000
## 2         2 0.7321429
## 3         3 0.7410714
## 4         4 0.7544643
## 5         5 0.7410714
## 6         6 0.7589286